<?php
/**
 * 
 *
 * @author Iain Edminster
 */
class Bliss_DataReport_Result_Item
{
	/**
	 * The result item's value
	 *
	 * @var string
	 */
	protected $_value;

	/**
	 * The item's column name
	 *
	 * @var string
	 */
	protected $_key;

	/**
	 * Optional format for the value
	 *
	 * @var string
	 */
	protected $_format;

	/**
	 * Whether the item is visible
	 *
	 * @var bool
	 */
	protected $_visible = false;

	/**
	 * Class construtor
	 *
	 * @param string $key
	 * @param string $value
	 */
	public function __construct($key, $value)
	{
		$this->_key		= $key;
		$this->_value	= $value;
	}

	/**
	 * Sets the item's value
	 *
	 * @param string $value
	 */
	public function setValue($value)
	{
		$this->_value	= $value;
	}

	/**
	 * Returns the item's formatted value
	 *
	 * @return string
	 */
	public function getValue()
	{
		if(!isset($this->_value)) return '';
		if(isset($this->_format)) {
			if($this->_format instanceOf Bliss_DataReport_Format_Abstract) {
				$this->_format->setValue($this->_value);
				return $this->_format->getValue();
			} else {
				return sprintf($this->_format, $this->_value);
			}
		} else {
			return $this->_value;
		}
	}

	/**
	 * Returns the raw value of the item
	 *
	 * @return string
	 */
	public function getRawValue()
	{
		return $this->_value;
	}

	/**
	 * Returns the item's key value
	 *
	 * @return string
	 */
	public function getKey()
	{
		return $this->_key;
	}

	/**
	 * Sets the item's format
	 *
	 * @param string $format
	 */
	public function setFormat($format)
	{
		$this->_format	= $format;
	}

	public function setVisible($visible=true)
	{
		$this->_visible = $visible;
	}

	public function isVisible()
	{
		return $this->_visible;
	}

	/**
	 * Returns the item's value
	 *
	 * @see getValue
	 * @return string
	 */
	public function __toString()
	{
		return $this->getValue();
	}
}
?>
